package com.sams.tag;


import java.io.IOException;


import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;


public class PageTag extends SimpleTagSupport{
	
	private String url;  
	private int currentPage;
	private int prePage;
	private int nextPage;
	private int totalPage;
	
	
 
	
	@Override
	public void doTag() throws JspException, IOException {
		
		 JspWriter out = this.getJspContext().getOut();
		  out.append("<nav aria-label=\"Page navigation\" style=\"text-align: center;\">");
		  out.append("<ul class=\"pagination\">");
		  out.append("<li>");
		  out.append("<a href=\""+url+"&currentPage="+prePage+"\" aria-label=\"Previous\">");
		  out.append("<span aria-hidden=\"true\">&laquo;</span>");
		  out.append("</a>");
		  out.append("</li>");
		  if(totalPage<=7) {
			  for(int i=1;i<=totalPage;i++) {
				  
				  if(currentPage==i) {
					  out.append(" <li class=\"active\">");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
				  }else {
					  out.append(" <li>");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
					  
				  }
				  
				  
			  }
			  
		  }else if(currentPage<4){
			  for (int i = 1; i <=7; i++) {
				  if(currentPage==i) {
					  out.append(" <li class=\"active\">");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
				  }else {
					  out.append(" <li>");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
					  
				  }
				
			  }


			}else if(totalPage-currentPage<3) {
				for (int i = totalPage-6; i<=totalPage; i++) {
					  if(currentPage==i) {
						  out.append(" <li class=\"active\">");
						  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
						  out.append("</li>");
					  }else {
						  out.append(" <li>");
						  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
						  out.append("</li>");
						  
					  }
					
				  }
			  
		  }else {
			  for(int i=currentPage-3;i<=currentPage+3;i++) {
				  if(currentPage==i) {
					  out.append(" <li class=\"active\">");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
				  }else {
					  out.append(" <li>");
					  out.append("<a href=\""+url+"&currentPage="+i+"\">"+i+"</a>");
					  out.append("</li>");
					  
				  }
			  }
		  }
		  
 
		  out.append("<li>");
		  out.append("<a href=\""+url+"&currentPage="+nextPage+"\" aria-label=\"Next\">");
		  out.append("<span aria-hidden=\"true\">&raquo;</span>");
		  out.append("</a>");
		  out.append("</li>");
		  
		  out.append("</ul>");
		  out.append("</nav>");
		 
  
		
	
		
	}








	public String getUrl() {
		return url;
	}








	public void setUrl(String url) {
		this.url = url;
	}








	public int getCurrentPage() {
		return currentPage;
	}








	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}








	public int getPrePage() {
		return prePage;
	}








	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}








	public int getNextPage() {
		return nextPage;
	}








	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}








	public int getTotalPage() {
		return totalPage;
	}








	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	
	


}